package com.andnnl.map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by chenss on 2020/4/27.
 */
public class ABC {
    String a;
    Integer b;
    String c;

    public ABC(String a, Integer b, String c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public static void main(String[] args) {
        List<ABC> last=new ArrayList<>();
        last.add(new ABC("a1",1,"c1"));
        last.add(new ABC("a2",2,"c2"));
        last.add(new ABC("a2",3,"c3"));

        Object rs=last.stream().collect(Collectors.toMap(x -> x.a
                , x ->  {HashMap<Integer,String> m= new HashMap<>(1);m.put(x.b,x.c);return m;}
                , (v1, v2) -> {v2.putAll(v1);return v2;}));

        Object rs2=last.stream().collect(Collectors.toMap(x -> x.a
                , x ->  getMap(x)
                , (v1, v2) -> {v2.putAll(v1);return v2;}));

        System.out.println(rs);
        System.out.println(rs2);
        //{a1={1=c1}, a2={2=c2, 3=c3}}
    }

    private static HashMap<Integer, String> getMap(ABC x) {
        HashMap<Integer, String> m = new HashMap<>(1);
        m.put(x.b, x.c);
        return m;
    }
}
